package com.shuai.dynamicProxy.jdk.proxy;

import com.shuai.staticProxy.impl.UserServiceImpl;
import com.shuai.staticProxy.service.UserService;
import lombok.Data;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.Arrays;

/**
 * @author shuaihong-coding
 * @date 2025/10/3
 * @className UserServiceInvocationHandler
 */
@Data
public class UserServiceInvocationHandler implements InvocationHandler {

    private UserService userService;
    public UserServiceInvocationHandler(UserService target) {
        this.userService = target;
    }
    public UserServiceInvocationHandler(){
        this.userService = new UserServiceImpl();
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("我是jdk动态代理 --- 我要开始查询用户" + Arrays.toString(args) + "的信息了");
        return method.invoke(userService, args);
    }
}
